package com.mingte.manghe.controller;

import com.alibaba.fastjson.JSONObject;
import com.mingte.manghe.annotation.LoginRequired;
import com.mingte.manghe.dto.TeaUserDTO;
import com.mingte.manghe.common.ResponseResult;
import com.mingte.manghe.exception.UpdateFailException;
import com.mingte.manghe.exception.UserNotExistExecption;
import com.mingte.manghe.utils.JwtUtils;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Api(tags = {"测试接口"})
@RequestMapping(value = "/hellow")
@RestController
public class HellowController extends BaseController{

    /*private final Logger logger = LoggerFactory.getLogger(HellowController.class);

    //@LoginRequired
    @ApiModelProperty("测试方法")
    @RequestMapping(value = "/get",method = RequestMethod.GET)
    public ResponseResult<List<TeaUserEntity>> hellow() throws UserNotExistExecption {
        TeaUserDTO teaUser = getTeaUser();
        logger.info("访问次数========================={}=={}",reqCount,teaUser);
        List<TeaUserEntity> teaUserList = teaUserService.getTeaUserList();
        return ResponseResult.success(teaUserList);
    }

    *//**
     * 登录并获取token
     * @return
     *//*
    @PostMapping("/login")
    public ResponseResult<TeaUserDTO> login(@RequestBody JSONObject jsonObject){
        String userName = jsonObject.getString("userName");
        String passWord = jsonObject.getString("passWord");
        // 检验用户是否存在(为了简单，这里假设用户存在，并制造一个uuid假设为用户id)
        String userId = UUID.randomUUID().toString();
        // 生成签名
        String token= JwtUtils.sign(userId);
        TeaUserDTO teaUserDTO = new TeaUserDTO();
        teaUserDTO.setUserId(userId);
        teaUserDTO.setUserName(userName);
        String encode = Base64.encode(passWord.getBytes());
        teaUserDTO.setPassWord(encode);
        teaUserDTO.setAccessMhToken(token);
        boolean setResult = redisUtils.set(userId, teaUserDTO);

        return setResult ? ResponseResult.success(teaUserDTO) : ResponseResult.fail("登录失败,稍后重试");
    }

    //@LoginRequired
    @ApiModelProperty("修改方法")
    @RequestMapping(value = "/update/user",method = RequestMethod.POST)
    public ResponseResult<List<TeaUserEntity>> getUserById(@RequestBody JSONObject jsonObject) throws UpdateFailException {
        TeaUserEntity teaUserEntity = jsonObject.getObject("teaUserEntity", TeaUserEntity.class);
        TeaTeamEntity teaTeamEntity = jsonObject.getObject("teaTeamEntity", TeaTeamEntity.class);

        logger.info("修改参数========================={}",teaUserEntity);
        logger.info("teaTeamEntity修改参数========================={}",teaTeamEntity);
        int i = teaUserService.updateTeaUserById(teaUserEntity.getTeacherId(), teaUserEntity.getTeamId(),teaTeamEntity);
        return i > 0 ? ResponseResult.success() : ResponseResult.fail();
    }*/
}
